package com.zhq.zhq_blog.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhq.zhq_blog.entity.Blog;
import com.zhq.zhq_blog.entity.RankingList;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * 排行榜mapper接口
 */
@Repository
public interface RankingListMapper extends BaseMapper<RankingList> {

    /**
     * 根据blog_id查询排行榜
     */
    @Select("select * from tb_ranking_list where blog_id = ${blogId}")
    RankingList queryRankingListByBlogId(@Param("blogId") Integer blogId);

    /**
     * 根据blog_id修改排行榜
     */
    @Update("update tb_ranking_list set flow = ${flow} where blog_id = ${blogId}")
    int updateByBlogId(@Param("blogId") Integer blogId, @Param("flow") Integer flow);

    /**
     * 根据blog_id删除排行榜
     */
    @Delete("delete from tb_ranking_list where blog_id = ${blogId}")
    int removeByBlogId(@Param("blogId") Integer blogId);
    /**
     * 分页查询排行榜
     * @param page
     * @param queryWrapper
     * @return
     */
    @Select("select * from tb_ranking_list ${ew.customSqlSegment}")
    IPage<RankingList> queryRankingListPage(Page<RankingList> page, @Param("ew") QueryWrapper<RankingList> queryWrapper);
}
